Skip to main content

Test setup

Overview

Registering contracts

Since we don't have native execution in the Rust backend yet, the only way to run contracts is to register the contract implementation for the given contract code identifier. In simpler words, we tell the environment "whenever you encounter this contract code, run this code that I've written instead".

Since this operation is specific to only the Rust debugger, it doesn't go through the mandos pipeline.

Setting accounts

Setting accounts in blackbox tests can be easily done by using a SetStateBuilder. In order to create an instance of the builder, we have to call the .account(...) method from ScenarioWorld.

world // ScenarioWorld struct
.account(USER_ADDRESS) // SetStateBuilder with USER_ADDRESS account
.nonce(1) // custom nonce
.balance(50) // egld balance
.esdt_balance(TRANSFER_TOKEN, 1000) // esdt balance
.esdt_nft_balance(NFT_TOKEN_ID, 1u64, 1u64, ManagedBuffer::new()); // nft balance

There are no mandatory fields, so we can only add the fields that we actually need. For example, if we only need to create the account and we don't care about other fields, world.account(ADDRESS) will compile.

However, there is no possibility to upgrade and existing account, so there can only be one set block per account.

We can also chain the set state declarations (if useful) as such:

    world
.account(first) // SetStateBuilder for account `first`
.nonce(1)
.balance(100)
.account(second) // SetStateBuilder for `second`, ends set state for `first`
.nonce(2)
.balance(300)
.esdt_balance(TOKEN_ID, 500); // end set state for `second`

Checking accounts

Similar to setting accounts, the framework provides a CheckStateBuilder that we can use to check state values. The check builder is instantiated using .check_account(...) from ScenarioWorld.

    world
.check_account(first) // CheckStateBuilder for `first`
.nonce(3)
.balance(100);

The same rules apply when chaining multiple account checks as for chaining accounts set.

    world
.check_account(first) // CheckStateBuilder for `first`
.nonce(3)
.balance(100);
.check_account(second) // CheckStateBuilder for `second`, ends check state for `first`
.check_storage("str:sum", "6");

Mandos trace

A mandos trace can quickly be generated by wrapping the integration test logic into the trace generation as such:

    world.start_trace();

// integration test logic

world.write_scenario_trace("trace1.scen.json");